package com.example.SBootDemo;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;
@ServletComponentScan
/**
 * 
 * @author HP
 *SpringBootApplication 上使用@ServletComponentScan 注解后
Servlet可以直接通过@WebServlet注解自动注册
Filter可以直接通过@WebFilter注解自动注册
Listener可以直接通过@WebListener 注解自动注册
 */
@SpringBootApplication
@MapperScan("com.example.SBootDemo.Dao")
public class SBootDemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(SBootDemoApplication.class, args);
//		mina监听8888端口
//		MinaTimeServer t = new MinaTimeServer();  
//		    new Thread(t).start();  
		 
	}
	
	
	
	//日期转换器  转换controller中 "yyyy-MM-dd HH:mm:ss"格式字符串 
	@Bean
    public Converter<String, Date> addNewConvert() {
        return new Converter<String, Date>() {
            @Override
            public Date convert(String source) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 Date date = null;
            try {
            	if(source==""||source.equals(null)){
            		date = new Date();
            	}else{
            		date = sdf.parse((String) source);
            	}
                
                } catch (Exception e) {
                e.printStackTrace();
                }
             return date;
            }
        };
    }
} 
